<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>订单管理</title>
    <!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.9/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span
            class="c-gray en">&gt;</span>
        订单列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
            title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div>
            <label for="">订单号：</label>
            <input type="text" class="input-text" style="width:220px" placeholder="输入订单号" id="orderNum" name="">
            <!-- 上级账号： -->
            <!-- <input type="text" class="input-text" style="width:150px" placeholder="输入上级账号" id="pollCode" name=""> -->
            <label for="">买家姓名：</label>
            <input type="text" class="input-text" style="width:150px" placeholder="输入买家姓名" id="buyerName" name="">
            <label for="">电话：</label>
            <input type="text" class="input-text" style="width:150px" placeholder="输入电话号码" id="mobile" name="">
            <label for="">物流单号：</label>
            <input type="text" class="input-text" style="width:150px" placeholder="输入电话号码" id="expressNo" name="">
            <label for="">订单类型：</label>
            <select  class="input-text" style="width:150px"  id="typeStatus" name="">
                <option value="">-请选择-</option>
                <option value="0">普通订单</option>
                <option value="1">礼包订单</option>
                <option value="2">礼品订单</option>
                <option value="3">抢购订单</option>
                <option value="4">热销订单</option>
                <option value="5">签到礼品订单</option>
            </select>
            <label for="">订单状态：</label>
            <select  class="input-text" style="width:150px"  id="status" name="">
                <option value="">-请选择-</option>
                <option value="1">待审核</option>
                <option value="3">待付款</option>
                <option value="6">待发货</option>
                <option value="9">待收货</option>
                <option value="11">已完成</option>
            </select>
            <button type="submit" class="btn btn-success" name="" data-type="reload" id="searach"><i class="Hui-iconfont">&#xe665;</i>
                搜索</button>
        </div>
        <table class="layui-hide" id="orderList" lay-filter="orderList"></table>
    </div>
    <input type="" name="details_id" id="details_id" value="" style="display:none;" />
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./../static/js/common.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="./../lib/layui/layui.js"></script>
    <script type="text/html" id="operation">
        {{#  if(d.expressType == 0){ }}
            {{#  if(d.status == 6){ }}
                <a  title="发货" lay-event="delieveGoods" class=""><i class="Hui-iconfont">&#xe669;</i></a>
            {{#  } else { }}
            {{#  } }}
        {{#  } else { }}
            {{#  if(d.status == 6){ }}
                <a  title="发货" lay-event="selfMention" class=""><i class="Hui-iconfont">&#xe669;</i></a>
            {{#  } else { }}
            {{#  } }}
        {{#  } }}
        <a  title="查看订单详情" lay-event="orderDetails"><i class="Hui-iconfont">&#xe687;</i></a>
        <!-- <a  title="取消订单" lay-event="cancel"><i class="Hui-iconfont">&#xe725;</i></a> -->
	  </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
          var insTable =   table.render({
                elem: '#orderList',
                cellMinWidth: 80,
                id: 'reload',
                url: admin_url + "/kvmOrder/orderAllInfoList",
                request: {
                    pageName: 'page',
                    limitName: 'size'
                },
                //额外的数据参数
                where: {
                    tokenUserId: userId,
                    token: token
                },
                method: 'post',
                // 回调
                done: function (res, curr, count) {
                    var data = res.data;
                    console.log(res)
                },
                paresData: function (res) {
                    return {
                        'data': res.data
                    }
                },
                response: {
                    statusCode: 200
                },
                page: 'true',
                cols: [[
                    { checkbox: true, align: 'center' },
                    { field: 'userName', title: '买家姓名', align: 'center' },
                    { field: 'address', title: '收货地址', align: 'center' },
                    { field: 'mobile', title: '电话', align: 'center' },
                    { field: 'createTime', title: '下单时间', align: 'center' },
                    { field: 'no', title: '订单号', align: 'center' },
                    { field: 'totalAmount', title: '支付金额', align: 'center' },
                    { field: 'expressName', title: '物流名称', align: 'center' },
                    { field: 'expressNo', title: '物流单号', align: 'center' },
                    {
                        field: 'expressType', title: '取货方式', align: 'center', templet: function (obj) {
                            if (obj.expressType == 0) {
                                return '<span  class="layui-badge layui-bg-green">物流</span>'
                            } else if (obj.expressType == 1) {
                                return '<span class="layui-badge layui-bg-blue">自提</span>'
                            }else if(obj.expressType == null){
                                return '<span></span>'
                            }
                        }
                    },
                    {
                        field: 'type', title: '订单类型', align: 'center', templet: function (obj) {
                            if (obj.type == 0) {
                                return '<span class="layui-badge layui-bg-blue">普通订单</span>'
                            } else if (obj.type == 1) {
                                return '<span class="layui-badge layui-bg-green">礼包订单</span>'
                            }else if(obj.type == 2){
                                return '<span class="layui-badge layui-bg-orange">礼品订单</span>'
                            }else if(obj.type == 3){
                                return '<span class="layui-badge layui-bg-cyan">抢购订单</span>'
                            }else if(obj.type == 4){
                                return '<span  class="layui-badge">热销订单</span>'
                            }else if(obj.type == 5){
                                return '<span class="layui-badge layui-bg-gray">签到礼品订单</span>'
                            }else {
                                return '<span></span>'
                            }
                        }
                    },
                    {
                        field: 'status', title: '订单状态', align: 'center', templet: function (obj) {
                             if (obj.status == 1) {
                                return '<span  class="layui-badge">待审核</span>'
                            }else if (obj.status == 3) {
                                return '<span class="layui-badge layui-bg-orange">待付款</span>'
                            }else if (obj.status == 6) {
                                return '<span class="layui-badge layui-bg-cyan">待发货</span>'
                            }else if (obj.status == 9) {
                                return '<span class="layui-badge layui-bg-blue">待收货</span>'
                            }else if (obj.status == 11) {
                                return '<span class="layui-badge layui-bg-green">已完成</span>'
                            }else {
                                return '<span></span>'
                            }
                        }
                    },
                    {feild:'payStatus',title:'支付状态',align:'center',templet:function(obj){
                        if(obj.payStatus == 0){
                            return '<span  class="layui-badge">待支付</span>'
                        }else if(obj.payStatus == 2){
                            return '<span class="layui-badge layui-bg-orange">支付失败</span>'
                        }else if(obj.payStatus == 4){
                            return '<span class="layui-badge layui-bg-cyan">支付成功</span>'
                        }else {
                            return '<span></span>'
                        }                                     
                    }},
                    {feild:'expressStatus',title:'物流状态',align:'center',templet:function(obj){
                        if(obj.expressStatus == 6){
                            return '<span  class="layui-badge">待发货</span>'
                        }else if(obj.expressStatus == 9){
                            return '<span class="layui-badge layui-bg-orange">待收货</span>'
                        }else if(obj.expressStatus == 11){
                            return '<span class="layui-badge layui-bg-cyan">已签收</span>'
                        }else {
                            return '<span></span>'
                        }
                    }},
                    { toolbar: '#operation', title: '操作' }
                ]]
            })
            $("#searach").on("click", function () {
                var orderNum = $("#orderNum").val(),
                        buyerName = $("#buyerName").val();
                insTable.reload({
					where: {
						"token": token,
						"tokenUserId": userId,
						"userName":buyerName,
						"no":orderNum,
                        'type':$("#typeStatus option:selected").val(),
                        'status':$("#status option:selected").val(),
                        'mobile':$("#mobile").val(),
                        'expressNo':$("#expressNo").val()
					}, page: {
                        curr: 1
                    }
				});

            })
            // 监听行操作栏事件。。可直接传值..
            table.on('tool(orderList)', function (obj) {
                var id = obj.data.id;
                if (obj.event === 'delieveGoods') {
                    // <div class="row cl" style="margin-top:10px;"><label style = "display:inline-block;width:70px;text-align:right"  >备注：</label><input style="width:150px"  class="input-text" type="text" id="remarks" placeholder="请输入备注"></div>
                    layer.confirm('<div style="text-align:center"><div class="row cl" style="margin-bottom:10px;"><label style = "display:inline-block;width:70px;text-align:right"  >物流名称：</label><input style="width:150px"  class="input-text" type="text" id="expressName" placeholder="请输入快递名"></div><div class="row cl"><label style = "display:inline-block;width:70px;text-align:right" >物流单号：</label><input style="width:150px"  class="input-text" id="courierNum" type="text" placeholder="请输入快递单号"></div></div>', { title: '发货方式:物流',area:['25%','25%'] }, function (obj) {
                        var remarks = $("#remarks").val();
                        if ($("#expressName").val() == '') {
                            layer.msg("请填写物流名称")
                        } else if ($("#courierNum").val() == "") {
                            layer.msg("请填写物流单号")
                        } else {
                            var expressName = $("#expressName").val(),
                                courierNum = $("#courierNum").val();
                            $.ajax({
                                type: 'post',
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmOrder/wlOrdersSend',
                                data: { tokenUserId: userId, token: token,orderId:id, expressNo:courierNum,expressName:expressName},
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('发货成功', {
                                            time: 1000,
                                            end: function () {
                                                // location.replace(location.href)
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg)
                                    }
                                }
                            })
                        }

                    })
                }else if (obj.event == 'selfMention') {
                    layer.confirm("是否确认发货", { title: '发货方式:自提' }, function () {
                        $.ajax({
                        type: 'post',
                        xhrFields: { withCredentials: true },
                        url: admin_url + '/kvmOrder/ztOrdersSend',
                        data: { tokenUserId: userId, token: token,orderId:id },
                        success: function (data) {
                        	if (data.code == 200) {
                        		layer.msg('发货成功', {
                        			time: 1000,
                        			end: function () {
                                        $(".layui-laypage-btn").click();
                        			}
                        		})
                        	} else {
                        		layer.msg(data.msg)
                        	}
                        }
                        })
                    })
                }else if(obj.event == 'orderDetails'){
                    var index = layer.open({
                        type: 2,
                        title: '订单详情',
                        id: id,
                        content: './orderDetails.html'
                    })
                    layer.full(index);
                    $("#details_id").val(id)
                }
            })
        })
    </script>
</body>

</html>